<?php

namespace App\Model\Backend;

use Illuminate\Database\Eloquent\Model;

class TemplatesModel extends Model
{
    protected $table = 'templates';
    protected $primaryKey = 'tid';

    public function templates(){
        $arr=array();
        $templates=$this->all();
        //$template_stages_task=new TemplatesStagesTaskModel();
        $stage=new ProjectStagesModel();
        foreach($templates as $k=>$v){
            $stages= explode(',',$v['stages_id']);
            $res=$stage->whereIn('sid',$stages)->pluck('name');
            $arr[$k]['templates_id']=$v['tid'];
            $arr[$k]['templates_name']=$v['name'];
            $arr[$k]['templates_type']=$v['project_type_name'];
            $arr[$k]['templates_type_id']=$v['project_type_id'];
            $arr[$k]['stages']=$res;
        }
        return $arr;
    }

}
